from rest_framework.response import Response
from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage,SKU
from meiduo_admin.serializers.images import SKUImageSerializer,SKUSerializer
from meiduo_admin.utils import PageNum



class ImageView(ModelViewSet):
    # 图片序列化器
    serializer_class = SKUImageSerializer
    # 图片查询集
    queryset = SKUImage.objects.all()
    # 分页
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]
    # 获取图片
    def simple(self,request):
        skus = SKU.objects.all()
        # 序列化返回ｓｋｕ商品
        ser = SKUSerializer(skus,many=True)
        return Response(ser.data)
